package com.pgytesting.secondhandcar.vo;

import com.pgytesting.secondhandcar.util.SessionUtil;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonInclude;

import javax.servlet.http.HttpSession;

/**
 * @author : frosty0804@gmail.com
 * @version : v1.0
 * @projectName : robot
 * @className : ResponseMessage
 * @description : TODO(请求响应信息类)
 * @date : 2019/6/16 11:23
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseMessage<T> {

    private String msg;
    private boolean success;
    private Integer code;
    private T data;
    private String sessionId;

    ResponseMessage(boolean success, String msg, Integer code, T data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
        this.code = code;
        this.sessionId = SessionUtil.getSession().getId();
    }

    ResponseMessage(boolean success, Integer code, T data) {
        this.success = success;
        this.data = data;
        this.code = code;
        this.sessionId = SessionUtil.getSession().getId();
    }

    ResponseMessage(boolean success, Integer code) {
        this.success = success;
        this.code = code;
        this.sessionId = SessionUtil.getSession().getId();
    }

    ResponseMessage(boolean success, String msg, Integer code) {
        this.success = success;
        this.msg = msg;
        this.code = code;
        this.sessionId = SessionUtil.getSession().getId();
    }


    public static ResponseMessage successResponse() {
        return new ResponseMessage(Boolean.TRUE, 200);
    }

    public static ResponseMessage successResponse(String msg) {
        return new ResponseMessage(Boolean.TRUE, msg, 200);
    }

    public static ResponseMessage successResponse(Object data) {
        return new ResponseMessage(Boolean.TRUE, 200, data);
    }

    public static ResponseMessage successResponse(Object data, String msg) {
        return new ResponseMessage(Boolean.TRUE, msg, 200, data);
    }

    public static ResponseMessage errorResponse() {
        return new ResponseMessage(Boolean.FALSE, 300);
    }

    public static ResponseMessage errorResponse(String msg) {
        return new ResponseMessage(Boolean.FALSE, msg, 300);
    }

    public static ResponseMessage errorResponse(Object data) {
        return new ResponseMessage(Boolean.FALSE, 300, data);
    }

    public static ResponseMessage errorResponse(String msg, Integer code) {
        return new ResponseMessage(Boolean.FALSE, msg, code);
    }
}
